#pragma once

#include "base_noncopyable.h"
#include <string>
#include <map>
#include <chrono>
#include <memory>

namespace El {
namespace Restful {

// 用户会话信息
struct UserSession {
    std::string username;
    std::string access_token;
    std::string refresh_token;
    std::chrono::system_clock::time_point access_token_expiry;
    std::chrono::system_clock::time_point refresh_token_expiry;
    std::string device_id;
    std::string role;
};

// 用户认证管理类
class AuthManager {
    DISALLOW_COPY_AND_MOVE(AuthManager);

public:
    static AuthManager &GetInstance();

    // 登录相关接口
    bool ValidateLogin(const std::string &username,
                      const std::string &password,
                      const std::string &device_id,
                      bool remember_me,
                      UserSession &session);

    // Token相关接口
    bool ValidateToken(const std::string &token, UserSession &session);
    bool RefreshToken(const std::string &refresh_token, UserSession &session);
    bool Logout(const std::string &access_token);

private:
    AuthManager() = default;

    // 内部辅助函数
    std::string GenerateToken(const std::string &username,
                             const std::string &device_id,
                             bool is_refresh_token);
    void CleanupExpiredSessions();
    
private:
    // 内部状态
    std::map<std::string, UserSession> active_sessions_;
    std::map<std::string, std::string> refresh_token_map_;
};

} // namespace Restful
} // namespace El
